package com.formation.tocea.library.client.listener;

import com.formation.tocea.library.client.ui.list.BookItem;
import com.formation.tocea.library.client.ui.list.BookTable;
import com.formation.tocea.library.client.ui.main.MainPanel;
import com.formation.tocea.library.client.ui.manager.BookManagerPanel;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.RootPanel;

public class AddBookListener implements ClickHandler {
	public void onClick(ClickEvent event) {
		MainPanel mainPanel = (MainPanel) RootPanel.get("mainPanel").getWidget(0);
		BookTable bookTable = null;
		if (mainPanel.getActiveWidget() != null) {
			if (mainPanel.getActiveWidget() instanceof BookManagerPanel) {
				BookManagerPanel bookManagerPanel = (BookManagerPanel) mainPanel.getActiveWidget();
				bookTable = bookManagerPanel.getBookTable();
				
				bookTable.getBookList().add(new BookItem(3, "La guerre des mondes", "Wells", "3211234344534", "Sci-fi", "2004"));
			}
		}
	}
}
